package com.woniuxy.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.woniuxy.entity.Unpack;
import com.woniuxy.service.UnpackService;
import com.woniuxy.utils.Result;

@Controller
@RequestMapping("/unpack")
public class UnpackController {
	@Autowired
	private UnpackService unpackService;
	@RequiresPermissions("manager:find")
	@RequestMapping("/all")
	@ResponseBody
	public Result<List<Unpack>> all(){
		Result<List<Unpack>> result = new Result<>();
		result.setData(unpackService.all());
		return result;
		
	}
	@RequiresPermissions("manager:add")
	@RequestMapping("/add")
	@ResponseBody
	public Result<List<Unpack>> addUnpack(Unpack unpack,int paid){
		Result<List<Unpack>> result = new Result<>();
		if(unpackService.addUnpack(unpack,paid)==1){
			result.setStatus(Result.SUCCESS);
			result.setMessage("成功");
		}else{
			result.setStatus(Result.ERROR);
			result.setMessage("no");
		}
		return result;
		
	}
	@RequiresPermissions("manager:update")
	@RequestMapping("/update")
	@ResponseBody
	public Result<List<Unpack>> updateUnpack(Unpack unpack){
		Result<List<Unpack>> result = new Result<>();
		if(unpackService.updateUnpack(unpack)==1){
			result.setStatus(Result.SUCCESS);
			result.setMessage("成功");
		}else{
			result.setStatus(Result.ERROR);
			result.setMessage("no");
		}
		return result;
		
	}
	@RequiresPermissions("manager:find")
	@RequestMapping("/allunpack")
	@ResponseBody
	public Result<List<Unpack>> allUnpack() {
		Result<List<Unpack>> result = new Result<>();
		result.setData( unpackService.allUnpack());
		return result;
	}
	
}
